package simplestore;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import name.fowler.refactoring.simplestore.Movie;
import name.fowler.refactoring.simplestore.PriceCodes;
import name.fowler.refactoring.simplestore.Rental;

public class RentalBuilder {
	private int m_daysRented = 0;
	private double m_rentalAmount = 0;
	private String m_movieTitle = "A test film";
	private PriceCodes m_moviePriceCode = PriceCodes.Regular;
	
	public final RentalBuilder whenDaysRented(int daysRented) {
		m_daysRented = daysRented;
		return this;
	}
	
	public final RentalBuilder whenRentalAmount(double rentalAmount) {
		m_rentalAmount = rentalAmount;
		return this;
	}
	
	public final RentalBuilder whenMovieTitle(final String movieTitle) {
		m_movieTitle = movieTitle;
		return this;
	}
	
	public final RentalBuilder whenMoviePriceCode(final PriceCodes moviePriceCode) {
		m_moviePriceCode = moviePriceCode;
		return this;
	}
	
	public final Rental build() {
		Movie movieMock = mock(Movie.class);
		when(movieMock.getPriceCode()).thenReturn(m_moviePriceCode);
		when(movieMock.getTitle()).thenReturn(m_movieTitle);

		Rental rentalMock = mock(Rental.class);
		when(rentalMock.getDaysRented()).thenReturn(m_daysRented);
		when(rentalMock.getAmount()).thenReturn(m_rentalAmount);
		when(rentalMock.getMovie()).thenReturn(movieMock);
		
		return rentalMock;
	}
}
